<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp" %>
<html>
  <head>
    <title>登录</title>
    <link href="${ctx}/css/main/base.css" rel="stylesheet" type="text/css"/>
	<link href="${ctx}/css/main/main.css" rel="stylesheet" type="text/css"/>
	 <script type="text/javascript">
    function userCreate(){
		
		window.location = "${ctx}/user/user!preCreateUser.action?user.userFlag=0";
		}
    function userModifyPsw(){
    	var userId = document.getElementById("userId").value;
    	
    	window.location = "${ctx}/user/user!preModifyPsw.action?user.userId="+userId;
    }
    </script>
  </head>
  <body class="m_6 m_r">
<div id="main">
  
  <div class="b_add font14 bg3">部门管理（${department.deptName}）</div>
<div id="info"><font color="red">${info}</font></div>
<form action="depart_modify.action" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab_1">
  <tr>
    <td style="font-size:12px;">部门排序号：</td>
    <td style="font-size:12px;"><input type="text" id="deptOrder" name="department.deptOrder" value="${department.deptOrder}" size="5" class="fl_l" /><div id="errOrder"></div>
      用于处于同一层次部门的排序，以及用户列表的排序</td>
  </tr>
  <tr>
    <td style="font-size:12px;">部门名称：</td>
    <td><input type="text" id="deptName" name="department.deptName" value="${department.deptName}" class="fl_l" /><div id="errName"></div></td>
  </tr>
  <tr>
    <td style="font-size:12px;">部门电话：</td>
    <td><input type="text" id="deptTel" name="department.deptTel" value="${department.deptTel}" class="fl_l" /><div id="errTel"></div></td>
  </tr>
  <tr>
    <td style="font-size:12px;">部门传真：</td>
    <td><input type="text" id="deptFax" name="department.deptFax" value="${department.deptFax}" class="fl_l" /><div id="errFax"></div></td>
  </tr>
  <tr>
    <td style="font-size:12px;">上级部门：</td>
    <td><select name="department.deptParent">
    <option value="0">--请选择上级部门--</option>
    <s:iterator value="departments" status="depart">
    <option value="${deptId}" <s:if test="department.deptParent == deptId">selected</s:if> >${deptNames}</option>
   </s:iterator>
    </select> </td>
  </tr>
   <tr>
    <td style="font-size:12px;">部门职能：</td>
    <td><textarea class="text1" name="department.deptFunc"></textarea></td>
  </tr>
  <tr>
    <td style="font-size:12px;">部门主管：</td>
    <td><input type="hidden" id="deptManager" name="department.deptManager" value="${department.deptManager}"/>
    <textarea class="text1" name="deptManagerName" >${department.deptManagerName}</textarea>
    <input type="button" onclick="chooseLeaders('deptManager','deptManagerName');" value="+添加" class="log_f">
     <input type="button" onclick="deleteChoose('deptManager','deptManagerName');" value="-清空" class="log_f">
    </td>
  </tr>
  <tr>
    <td style="font-size:12px;">上级主管领导：</td>
    <td>
    <input type="hidden" id="deptLeader1" name="department.deptLeader1" value="${department.deptLeader1}"/>
    <textarea class="text1" name="deptLeader1Name">${department.deptLeader1Name}</textarea>
      <input type="button" onclick="chooseLeaders('deptLeader1','deptLeader1Name');" value="+添加" class="log_f">
     <input type="button" onclick="deleteChoose('deptLeader1','deptLeader1Name');" value="-清空" class="log_f">
    </td>
  </tr>
  <tr>
    <td style="font-size:12px;">上级分管领导：</td>
    <td><input type="hidden" id="deptLeader2" name="department.deptLeader2" value="${department.deptLeader2}"/>
    <textarea class="text1" name="deptLeader2Name">${department.deptLeader2Name}</textarea>
    <input type="button" onclick="chooseLeaders('deptLeader2','deptLeader2Name');" value="+添加" class="log_f">
     <input type="button" onclick="deleteChoose('deptLeader2','deptLeader2Name');" value="-清空" class="log_f">
    </td>
  </tr>
  <tr>
    <td colspan="2"><div class="zc_but2">
    <input type="hidden" name="department.deptId" value="${department.deptId}"/>
	<input type="button" onclick="modifyDepart();" value="修改" class="log_f zc_b">
	<input type="button" onclick="javascript:reset();" value="重置" class="log_f zc_b">
	<input type="button" onclick="javascript:history.go(-1);" value="返回" class="log_f zc_b">
	</div></td>
    </tr>
  </table>
  
  <div class="b_add font14 bg3">添加/删除部门</div>
  <div align="center">
  <input  type="button" onclick="addDepartment();" value="添加子部门" class="log_f2">
  <input  type="button" onclick="deleteDepart();" value="删除该部门" class="log_f2">
  </div>
</div>
</form>
</body>
</html>
<script type="text/javascript" src="${ctx}/scripts/commons/validation.js"></script>
<script type="text/javascript">
<!--
function modifyDepart(){
 var deptName = document.getElementById("deptName").value;
 var deptOrder = document.getElementById("deptOrder").value;
 var deptTel = document.getElementById("deptTel").value;
 var deptFax = document.getElementById("deptFax").value;
 
 
 if(deptOrder.length == 0 || deptOrder == ""){
    document.getElementById("errOrder").innerHTML = "<font color='red'>部门排序不能为空!</font>";
	   return false;
 }
 if(isNaN(parseInt(deptOrder))){
    document.getElementById("errOrder").innerHTML = "<font color='red'>部门排序必须是数字!</font>";
	   return false;
 }
 if(deptOrder.length > 4){
    document.getElementById("errOrder").innerHTML = "<font color='red'>部门排序长度不能超过4!</font>";
	   return false;
 }
 if(deptName.length == 0 || deptName == ""){
    document.getElementById("errName").innerHTML = "<font color='red'>部门名称不能为空!</font>";
	   return false;
 }
 if(deptName.length > 0 && hasSpecialChart(deptName)){
	document.getElementById("errName").innerHTML = "<font color='red'> 部门名称不能有特殊字符!</font>";
		return false;
}
 if(deptName.length > 50){
	document.getElementById("errName").innerHTML = "<font color='red'> 部门名称长度不能超过50!</font>";
		return false;
}
if(deptTel.length > 0 && !isAllNumber(deptTel)){
	document.getElementById("errTel").innerHTML = "<font color='red'> 正确填写电话号码!</font>";
	return false;
}
if(deptTel.length > 20 ){
	document.getElementById("errTel").innerHTML = "<font color='red'> 正确填写电话号码!</font>";
	return false;
}
if(deptFax.length > 20){
	document.getElementById("errFax").innerHTML = "<font color='red'> 正确填写传真号码!</font>";
	return false;
}
document.forms[0].submit();

}

//添加子部门
function addDepartment(){

window.location = "${ctx}/depart/depart!preCreateDept.action?department.deptParent=<s:property value="department.deptId"/>";
}


//删除部门
function deleteDepart(){

if(window.confirm("确定要删除该部门?")){
document.forms[0].action = "${ctx}/depart/depart_delete.action";
document.forms[0].submit();

}
}


function deleteChoose(id,name){
		document.getElementById(id).value = "";
    	document.getElementById(name).value = "";
	}
	
	
function chooseLeaders(id,name){

	var names ="";
       var ids ="";
	var item=window.showModalDialog("${ctx}/user/user!chooseUser.action?time="+new Date().getTime(),window,"scroll:no;dialogHeight=420px;dialogWidth=420px;");
    if(item != null){
    for(var i=0;i<item.length;i++)
       {
          names += item[i][0]+",";
          ids += item[i][1]+",";
       }
     
   	document.getElementById(id).value = ids;
   	document.getElementById(name).value = names;
}
}
//-->
</script>